import java.lang.reflect.Field;

/**
 * @License: (C) Copyright 2013-2022
 * @Contact: abcque@outlook.com
 * @IDE: IntelliJ IDEA
 * @Encoding: utf-8
 * @Project: st2214st2215
 * @Package: PACKAGE_NAME
 * @File: PersonTest.java
 * @Time: 2023/5/30 15:06
 * @Author: abcque
 * @Description:
 * @Modifier:
 * @ModifyDate:
 * @ModifyRemark:
 */
public class PersonTest {
    public static void main(String[] args) {
        // Person person = new Person("abc", 18);
        //
        // // person.setName("abc");
        // // person.setAge(18);
        //
        // System.out.println(person.toString());

        String className = "Person";

        try {
            Class<?> clazz = Class.forName(className);
            // 调用默认构造器创建一个对象
            Object object = clazz.newInstance();
            // 获取 name 属性，注意：一定是公有权限
            Field nameField = clazz.getField("name");
            nameField.set(object, "abc");

            Object object1 = nameField.get(object);
            System.out.println(object1);

        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchFieldException e) {
            e.printStackTrace();
        }

    }
}
